package com.x.erp.manage;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.x.erp.dao.StockAgeDao;
import com.x.erp.model.StockAge;
import com.x.framework.manage.BaseManage;

/**
 * 库龄信息Mapper
 */
@Service
public class StockAgeManage extends BaseManage {

	@Autowired
	private StockAgeDao stockAgeDao;// 库龄信息DAO

	/**
	 * 修改库龄信息任务
	 * @param stockAge
	 * @return
	 * @throws Exception 
	 */
	public int updateStockAgeTask(StockAge stockAge) throws Exception {
		List<StockAge> stockAges = stockAgeDao.selectStockAgeList(stockAge);
		int i = 0;
		if(stockAges != null) {
			for(StockAge age : stockAges) {
				if(!this.getDate(age.getStockAgeFrom(), "yyyy-MM-dd").equals("1900-01-01")) {
					age.setStockAgeFrom(this.getDate(age.getStockAgeFrom(), 1));
				}
				age.setStockAgeTo(this.getDate(age.getStockAgeTo(), 1));
				i += this.update(age);
			}
		}
		return i;
	}

}
